package com.aliothservice.catfish.order.data;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

import org.springframework.data.annotation.Id;

public class ProductOrder {
	
	public final static String STATUS_UNPAID = "unpaid";
	public final static String STATUS_SHIP_PENDING = "ship_pending";
	public final static String STATUS_SHIPPED = "shipped";
	public static final String STATUS_REVIEW_PENDING = "review_pending";
	public static final String STATUS_COMPLETED = "completed";
	public static final String STATUS_CANCELED = "canceled";
	
	public static final String STATUS_APPEAL_ONGOING = "appeal_ongoing";

	public Map<String, Object> toMap(String phoneNumberMask) {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("id", this.getId());
		map.put("buyerName", this.getBuyerName());
		map.put("sellerName", this.getSellerName());
		if (null != phoneNumberMask) {
			if (0 == phoneNumberMask.compareTo(this.getBuyerId())) {
				map.put("buyerPhoneNumber", this.getBuyerPhoneNumber());
				if (this.getSellerPhoneNumber().length() != 11) {
					map.put("sellerPhoneNumber", this.getSellerPhoneNumber());
				} else {
					String maskedPhoneNumber = String.format("%s*****%s", this.getSellerPhoneNumber().substring(0, 2), this.getSellerPhoneNumber().substring(7, 10));
					map.put("sellerPhoneNumber", maskedPhoneNumber);
				}
				if (this.getManInChargePhoneNumber().length() != 11) {
					map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
				} else {
					String maskedPhoneNumber = String.format("%s*****%s", this.getManInChargePhoneNumber().substring(0, 2), this.getManInChargePhoneNumber().substring(7, 10));
					map.put("manInChargePhoneNumber", maskedPhoneNumber);
				}
			} else {
				map.put("sellerPhoneNumber", this.getSellerPhoneNumber());
				map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
				if (this.getBuyerPhoneNumber().length() != 11) {
					map.put("buyerPhoneNumber", this.getBuyerPhoneNumber());
				} else {
					String maskedPhoneNumber = String.format("%s*****%s", this.getBuyerPhoneNumber().substring(0, 2), this.getBuyerPhoneNumber().substring(7, 10));
					map.put("buyerPhoneNumber", maskedPhoneNumber);
				}
			}
		} else {
			map.put("buyerPhoneNumber", this.getBuyerPhoneNumber());
			map.put("sellerPhoneNumber", this.getSellerPhoneNumber());
			map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
		}
		map.put("buyerAddress", this.getBuyerAddress());
		map.put("volume", this.getVolume());
		if (null != this.getBuyerNote()) {
			map.put("buyerNote", this.getBuyerNote());
		}
		map.put("unitPrice", this.getUnitPrice());
		map.put("name", this.getName());
		map.put("title", this.getTitle());
		map.put("category", this.getCategory());
		map.put("origin", this.getOrigin());
		map.put("manInChargeName", this.getManInChargeName());
		DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS");
		map.put("creationDate", fullFormatter.format(this.getCreationDate()));
		map.put("lastUpdateTime", fullFormatter.format(this.getLastUpdateTime()));
		if (null != this.getPaidDate()) {
			map.put("paidDate", fullFormatter.format(this.getPaidDate()));
		}
		if (null != this.getAppealSubmissionDate()) {
			map.put("appealSubmissionDate", fullFormatter.format(this.getAppealSubmissionDate()));
		}
		map.put("productPhotoId", this.getProductPhotoId());
		map.put("orderNumber", this.getOrderNumber());
		if (null != this.getAlipayOrderNumber()) {
			map.put("alipayOrderNumber", this.getAlipayOrderNumber());
		}
		if (null != this.getBuyerReview()) {
			map.put("buyerReview", this.getBuyerReview());
		}
		if (null != this.getBuyerStarCount()) {
			map.put("buyerStarCount", this.getBuyerStarCount());
		}
		if (null != this.getSellerReview()) {
			map.put("sellerReview", this.getSellerReview());
		}
		if (null != this.getSellerStarCount()) {
			map.put("sellerStarCount", this.getSellerStarCount());
		}
		map.put("status", this.getStatus());
		if (null != this.getRefundAmount()) {
			map.put("refundAmount", this.getRefundAmount());
		}
		if (null != this.getAppealDescription()) {
			map.put("appealDescription", this.getAppealDescription());
		}
		if (null != this.getServiceId()) {
			map.put("serviceId", this.getServiceId());
		}
		
		return map;
	}
	
	@Id
	private String id;
	private String serviceId;

	// contact info
	private String buyerId;
	private String sellerId;
	private String buyerName;
	private String buyerPhoneNumber;
	private String sellerName;
	private String sellerPhoneNumber;
	
	// order info
	private String buyerAddress;
	private Integer volume;
	private String buyerNote;
	
	// service info
	private Float unitPrice;
	private String name;
	private String title;
	private String category;
	private String origin;
	private String manInChargeName;
	private String manInChargePhoneNumber;
	private String productPhotoId;
	
	private String orderNumber;
	private String alipayOrderNumber;
	
	private String buyerReview;
	private Integer buyerStarCount;
	private String sellerReview;
	private Integer sellerStarCount;
	
	private String status;
	
	private LocalDateTime creationDate;
	private LocalDateTime paidDate;
	private LocalDateTime lastUpdateTime;
	
	private LocalDateTime appealSubmissionDate;
	private Integer refundAmount;
	private String appealDescription;
	
	private String paymentUrl;
	
	public String getBuyerAddress() {
		return buyerAddress;
	}

	public void setBuyerAddress(String buyerAddress) {
		this.buyerAddress = buyerAddress;
	}

	public Integer getVolume() {
		return volume;
	}

	public void setVolume(Integer volume) {
		this.volume = volume;
	}

	public String getBuyerNote() {
		return buyerNote;
	}

	public void setBuyerNote(String buyerNote) {
		this.buyerNote = buyerNote;
	}

	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public String getBuyerId() {
		return buyerId;
	}
	
	public void setBuyerId(String buyerId) {
		this.buyerId = buyerId;
	}
	
	public String getSellerId() {
		return sellerId;
	}
	
	public void setSellerId(String sellerId) {
		this.sellerId = sellerId;
	}
	
	public String getBuyerName() {
		return buyerName;
	}
	
	public void setBuyerName(String buyerName) {
		this.buyerName = buyerName;
	}
	
	public String getBuyerPhoneNumber() {
		return buyerPhoneNumber;
	}
	
	public void setBuyerPhoneNumber(String buyerPhoneNumber) {
		this.buyerPhoneNumber = buyerPhoneNumber;
	}
	
	public String getSellerName() {
		return sellerName;
	}
	
	public void setSellerName(String sellerName) {
		this.sellerName = sellerName;
	}
	
	public String getSellerPhoneNumber() {
		return sellerPhoneNumber;
	}
	
	public void setSellerPhoneNumber(String sellerPhoneNumber) {
		this.sellerPhoneNumber = sellerPhoneNumber;
	}

	public Float getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(Float unitPrice) {
		this.unitPrice = unitPrice;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getOrigin() {
		return origin;
	}

	public void setOrigin(String origin) {
		this.origin = origin;
	}

	public String getManInChargeName() {
		return manInChargeName;
	}

	public void setManInChargeName(String manInChargeName) {
		this.manInChargeName = manInChargeName;
	}

	public String getManInChargePhoneNumber() {
		return manInChargePhoneNumber;
	}

	public void setManInChargePhoneNumber(String manInChargePhoneNumber) {
		this.manInChargePhoneNumber = manInChargePhoneNumber;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public LocalDateTime getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(LocalDateTime creationDate) {
		this.creationDate = creationDate;
	}

	public LocalDateTime getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(LocalDateTime lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	public String getOrderNumber() {
		return orderNumber;
	}

	public void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}

	public String getProductPhotoId() {
		return productPhotoId;
	}

	public void setProductPhotoId(String productPhotoId) {
		this.productPhotoId = productPhotoId;
	}

	public String getBuyerReview() {
		return buyerReview;
	}

	public void setBuyerReview(String buyerReview) {
		this.buyerReview = buyerReview;
	}

	public String getSellerReview() {
		return sellerReview;
	}

	public void setSellerReview(String sellerReview) {
		this.sellerReview = sellerReview;
	}

	public Integer getSellerStarCount() {
		return sellerStarCount;
	}

	public void setSellerStarCount(Integer sellerStarCount) {
		this.sellerStarCount = sellerStarCount;
	}

	public Integer getBuyerStarCount() {
		return buyerStarCount;
	}

	public void setBuyerStarCount(Integer buyerStarCount) {
		this.buyerStarCount = buyerStarCount;
	}

	public LocalDateTime getPaidDate() {
		return paidDate;
	}

	public void setPaidDate(LocalDateTime paidDate) {
		this.paidDate = paidDate;
	}

	public String getAlipayOrderNumber() {
		return alipayOrderNumber;
	}

	public void setAlipayOrderNumber(String alipayOrderNumber) {
		this.alipayOrderNumber = alipayOrderNumber;
	}

	public LocalDateTime getAppealSubmissionDate() {
		return appealSubmissionDate;
	}

	public void setAppealSubmissionDate(LocalDateTime appealSubmissionDate) {
		this.appealSubmissionDate = appealSubmissionDate;
	}

	public Integer getRefundAmount() {
		return refundAmount;
	}

	public void setRefundAmount(Integer refundAmount) {
		this.refundAmount = refundAmount;
	}

	public String getAppealDescription() {
		return appealDescription;
	}

	public void setAppealDescription(String appealDescription) {
		this.appealDescription = appealDescription;
	}

	public String getServiceId() {
		return serviceId;
	}

	public void setServiceId(String serviceId) {
		this.serviceId = serviceId;
	}

	public String getPaymentUrl() {
		return paymentUrl;
	}

	public void setPaymentUrl(String paymentUrl) {
		this.paymentUrl = paymentUrl;
	}

}
